﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Project
{
    public partial class txt_age : Form
    {
        public int id;
        public txt_age()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void SKxiu_Load(object sender, EventArgs e)
        {
            string sql = "select * from CetaeClass";
            DataTable dt = DBHelper.SelectForTable(sql);
            this.comboBox1.DisplayMember = "CetaeName";
            this.comboBox1.ValueMember = "CetaeId";
            this.comboBox1.DataSource = dt;
            s();
          
        }
        public void s() 
        {
            string sql = "select * from SuiKeInfo where SkeId="+id;
            SqlDataReader reader = DBHelper.SelectMore(sql);
            if (reader.Read())
            {
                this.txt_name.Text = reader["SkName"].ToString();
                this.txt_phoer.Text = reader["SkPhone"].ToString();
                this.txt_haoma.Text = reader["SkHao"].ToString();
                if (reader["SkAge"].ToString().Equals("男"))
                {
                    this.radioButton2.Checked = true;
                }
                else
                {
                   this.radioButton1.Checked = true;
                }
                this.txt_Address.Text = reader["SkAddress"].ToString();
                this.comboBox1.SelectedValue = reader["SktaeClass"];
                this.txt_nian.Text = reader["SkAge"].ToString();
            }
            reader.Close();

        }

        private void button1_Click(object sender, EventArgs e)
        {
          string name=  this.txt_name.Text;
          string phoer=  this.txt_phoer.Text;
          string haoma=   this.txt_haoma.Text;
          string address=  this.txt_Address.Text ;
          int hh=Convert.ToInt32(comboBox1.SelectedValue) ;
          string age = this.txt_nian.Text;
          string gender = this.radioButton1.Checked ? "男" : "女";

          if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(phoer) || string.IsNullOrEmpty(haoma))
          {
              MessageBox.Show("请填写完整信息");
              return;
          }
          string sql = string.Format("update  SuiKeInfo set SkName='{0}',SkSex='{1}',SkAge='{2}',SkPhone='{3}',SkAddress='{4}',SktaeClass={5},SkHao='{6}' where SkeId={7}", name, gender, age, phoer, address, hh, haoma,id);
          int result = DBHelper.ExecuteUpdate(sql);
            if(result > 0)
            {
                MessageBox.Show("修改成功！");
            }
            else 
            {
                MessageBox.Show("修改失败！");
            }
        }
    }
}
